package fun.qu_an.minecraft.fabric.fzbbl.event;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public final class PistonEvents {
	public static final Event<PistonExtending> EXTENDING = EventFactory.createArrayBacked(PistonExtending.class,
		listeners -> (world, pos, pistonState) -> {
			for (PistonExtending listener : listeners) {
				if (!listener.extending(world, pos, pistonState)) {
					return false;
				}
			}
			return true;
		});

	public static final Event<PistonExtended> EXTENDED = EventFactory.createArrayBacked(PistonExtended.class,
		listeners -> (world, pos, pistonState) -> {
			for (PistonExtended listener : listeners) {
				listener.extended(world, pos, pistonState);
			}
		});

	public static Event<PistonContracting> CONTRACTING = EventFactory.createArrayBacked(PistonContracting.class,
		listeners -> (world, pistonPos, pistonState) -> {
			for (PistonContracting listener : listeners) {
				if (!listener.contracting(world, pistonPos, pistonState)) {
					return false;
				}
			}
			return true;
		});

	public static Event<PistonContracted> CONTRACTED = EventFactory.createArrayBacked(PistonContracted.class,
		listeners -> (world, pos, pistonState) -> {
			for (PistonContracted listener : listeners) {
				listener.contracted(world, pos, pistonState);
			}
		});

	@FunctionalInterface
	public interface PistonExtending {
		@SuppressWarnings("BooleanMethodIsAlwaysInverted")
		boolean extending(World world, BlockPos pistonPos, BlockState pistonState);
	}

	@FunctionalInterface
	public interface PistonExtended {
		void extended(World world, BlockPos pistonPos, BlockState pistonState);
	}

	@FunctionalInterface
	public interface PistonContracting {
		@SuppressWarnings("BooleanMethodIsAlwaysInverted")
		boolean contracting(World world, BlockPos pistonPos, BlockState pistonState);
	}

	@FunctionalInterface
	public interface PistonContracted {
		void contracted(World world, BlockPos pistonPos, BlockState pistonState);
	}
}
